<template>
	<view>
		<scroll-view scroll-y>
			<uni-card :shadow="false" v-for="(it, index) in booksList">
				<view style="uni-flex uni-column">
					<view style="font-size:12pt;color:#000;padding:10rpx 0;">
						<text>{{it.shopName}} {{it.address}}</text>
					</view>
					<view style="font-size:10pt;padding:10rpx 0;">
						<text>{{it.linkman}}</text>
						<text style="padding-left:20rpx;">{{it.phone}}</text>
					</view>
				</view>
				<view style="border:1rpx solid #f5f5f5;margin:10rpx 0;"></view>
				<view class="uni-flex uni-row" style="justify-content:space-between;">
					<view>
						<!-- <text>默认地址</text>
						<switch checked /> -->
					</view>
					<view class="uni-flex uni-row" style="font-size:10pt;padding:10rpx;align-items:flex-end;">
						<view @click="onEdit(index)">编辑</view>
						<view style="padding-left:30rpx;" @click="onDelete(index)">删除</view>
					</view>
				</view>
			</uni-card>
			<view style="padding:60rpx 0;"></view>
		</scroll-view>
		<view class="uni-flex uni-row uni-bg-white" 
			style="position:fixed; bottom:0;padding: 20rpx 0;width:100%;align-items:center;justify-content:space-between;">
			<button @click="onClickToAddressAdd"
				style="background-color:#FF4D4F;color:#F8F8F8;font-size:12pt;width:90%;">添加地址</button>
		</view>
	</view>
</template>

<script>
	import { post } from '@/util/request.js';
	import { getBooksList } from '@/util/express_api.js';
	export default {
		data() {
			return {
				booksList: []
			}
		},
		onLoad() {
			this.getBooksList();
		},
		methods: {
			onClickToAddressAdd() {
				uni.navigateTo({
					url: '/pages/address/address_add'
				});
			},
			getBooksList() {
				var that = this;
				var userInfo = uni.getStorageSync('userInfo');
				if (userInfo != null && userInfo != '') {
					getBooksList({
						userId: userInfo.userId
					}).then(data => {
						that.booksList = data;
					});
				}
			},
			onEdit(index) {
				var that = this;
				var books = that.booksList[index];
				uni.navigateTo({
					url: '/pages/address/address_edit?books=' + encodeURIComponent(JSON.stringify(books))
				})
			},
			onDelete(index) {
				var that = this;
				var books = that.booksList[index];
				post('express/books/remove', {
					booksIdList: [books.booksId]
				}).then(res => {
					if (res.data) {
						that.getBooksList();
					}
				})
			}
		}
	}
</script>

<style>

</style>
